Persist all the Xen-API data values for VMs.
authorEwan Mellor <ewan@xensource.com>
Sat, 16 Dec 2006 12:49:23 +0000 (12:49 +0000)
committerEwan Mellor <ewan@xensource.com>
Sat, 16 Dec 2006 12:49:23 +0000 (12:49 +0000)
Signed-off-by: Ewan Mellor <ewan@xensource.com>
tools/python/xen/xend/XendAPI.py
tools/python/xen/xend/XendConfig.py
tools/python/xen/xend/XendDomain.py
tools/python/xen/xend/XendDomainInfo.py

index c43ae75976b40fb8554d6b95aec50d76a940d94e..540ab2e45d8daf572df159ab7f9bb17d3c62420d 100644 (file)
@@ -663,7 +663,10 @@ class XendAPI:
             XendDomain.instance().get_vm_by_uuid(vm_ref).info[name])
 
     def VM_set(self, name, session, vm_ref, value):
-        XendDomain.instance().get_vm_by_uuid(vm_ref).info[name] = value
+        xd = XendDomain.instance()
+        dominfo = xd.get_vm_by_uuid(vm_ref)
+        dominfo.info[name] = value
+        xd.managed_config_save(dominfo)
         return xen_api_success_void()
 
     # attributes (ro)
index e80422eaaa54ea5006d8cc775e1ef91afb6bec9e..113dc4c42cc8b799fa3f276a5f35805aca855b8a 100644 (file)
@@ -430,8 +430,12 @@ class XendConfig(dict):
         """
         cfg = {}
 
-        # First step is to convert deprecated options to
-        # current equivalents.
+        for key, typ in XENAPI_CFG_TYPES.items():
+            val = sxp.child_value(sxp_cfg, key)
+            if val is not None:
+                cfg[key] = typ(val)
+
+        # Convert deprecated options to current equivalents.
         
         restart = sxp.child_value(sxp_cfg, 'restart')
         if restart:
@@ -576,6 +580,11 @@ class XendConfig(dict):
         """
         cfg = self._parse_sxp(sxp_cfg)
 
+        for key, typ in XENAPI_CFG_TYPES.items():
+            val = cfg.get(key)
+            if val is not None:
+                self[key] = typ(val)
+
         # Convert parameters that can be directly mapped from
         # the Legacy Config to Xen API Config
         
@@ -590,9 +599,13 @@ class XendConfig(dict):
             except KeyError:
                 pass
 
-        self['PV_bootloader']      = cfg.get('bootloader',      '')
-        self['PV_bootloader_args'] = cfg.get('bootloader_args', '')
-        
+        def update_with(n, o):
+            if not self.get(n):
+                self[n] = cfg.get(o, '')
+
+        update_with('PV_bootloader',      'bootloader')
+        update_with('PV_bootloader_args', 'bootloader_args')
+
         image_sxp = sxp.child_value(sxp_cfg, 'image', [])
         if image_sxp:
             self.update_with_image_sxp(image_sxp)
@@ -760,11 +773,8 @@ class XendConfig(dict):
 
         self.validate()
 
-    def to_xml(self):
-        """Return an XML string representing the configuration."""
-        pass
-
-    def to_sxp(self, domain = None, ignore_devices = False, ignore = []):
+    def to_sxp(self, domain = None, ignore_devices = False, ignore = [],
+               legacy_only = True):
         """ Get SXP representation of this config object.
 
         Incompat: removed store_mfn, console_mfn
@@ -785,6 +795,11 @@ class XendConfig(dict):
         if domain.getDomid() is not None:
             sxpr.append(['domid', domain.getDomid()])
 
+        if not legacy_only:
+            for name in XENAPI_CFG_TYPES.keys():
+                if name in self and self[name] not in (None, []):
+                    sxpr.append([name, str(self[name])])
+
         for xenapi, legacy in XENAPI_CFG_TO_LEGACY_CFG.items():
             if self.has_key(xenapi) and self[xenapi] not in (None, []):
                 if type(self[xenapi]) == bool:
index b0a8de6a0a5a650b2b6d9a94ac0ac4626ce61dda..81c39384d40cb60412ac3e386fc196edf93bcc93 100644 (file)
@@ -284,7 +284,8 @@ class XendDomain:
                 fd, fn = tempfile.mkstemp()
                 f = os.fdopen(fd, 'w+b')
                 try:
-                    prettyprint(dominfo.sxpr(), f, width = 78)
+                    prettyprint(dominfo.sxpr(legacy_only = False), f,
+                                width = 78)
                 finally:
                     f.close()
                 try:
index 8b90814db2da95d978bb4a7fdc288252644c5a20..27dcce7e715fd8cf4eeaa7791063b575071fcf9b 100644 (file)
@@ -1800,9 +1800,10 @@ class XendDomainInfo:
         log.trace("XendDomainInfo.update done on domain %s: %s",
                   str(self.domid), self.info)
 
-    def sxpr(self, ignore_store = False):
+    def sxpr(self, ignore_store = False, legacy_only = True):
         result = self.info.to_sxp(domain = self,
-                                   ignore_devices = ignore_store)
+                                  ignore_devices = ignore_store,
+                                  legacy_only = legacy_only)
 
         if not ignore_store and self.dompath:
             vnc_port = self.readDom('console/vnc-port')